//
//  QDMineViewController.m
//  qidianchelian
//
//  Created by 冯贺 on 2018/4/18.
//  Copyright © 2018年 冯贺. All rights reserved.
//

#import "QDMineViewController.h"
#import "QDMineTableViewCell.h"
#import "QDAboutViewController.h"
#import "QDOrdersViewController.h"


@interface QDMineViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSArray * iconImgArr;
    NSArray * titleArr;
    
    UILabel * nameLabel;
}
@property(nonatomic,strong)UITableView * myTableView;
@end

@implementation QDMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    iconImgArr = @[@"orders",@"cars",@"clear",@"about"];
    titleArr = @[@"我的订单",@"我的车辆",@"清除缓存",@"关于我们"];
    [self.contentView addSubview:self.myTableView];
    
    UIButton * exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    exitBtn.frame = CGRectMake(15*bili, self.contentView.height-150*bili, SCREEN_WIDTH-30*bili, 45*bili);
    [exitBtn setTitle:@"退 出 登 录" forState:UIControlStateNormal];
    [exitBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    exitBtn.backgroundColor = [UIColor whiteColor];
    exitBtn.clipsToBounds = YES;
    exitBtn.layer.cornerRadius = 8;
    [exitBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    exitBtn.titleLabel.font = [UIFont systemFontOfSize:16*bili];
    [self.myTableView addSubview:exitBtn];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 215*bili;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55*bili;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    QDMineTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[QDMineTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.backgroundColor = kBackgroudColor;
    cell.iconImg.image = [UIImage imageNamed:iconImgArr[indexPath.row]];
    cell.titleL.text = titleArr[indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        QDOrdersViewController * vc = [[QDOrdersViewController alloc]initWithTitle:@"我的订单" isHidden:NO];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        
    }else if (indexPath.row == 2){
        [SMGlobalMethod showMessage:@"清除缓存成功"];
    }else{
        QDAboutViewController * vc = [[QDAboutViewController alloc]initWithTitle:nil isHidden:YES];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    SNUserInfoModel * model = [SNAccountTool getUserInfo];
    UIImageView * headerImage = [[UIImageView alloc]init];
    headerImage.image = [UIImage imageNamed:@"mineBack"];
    headerImage.userInteractionEnabled = YES;
    
    UIButton * iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    iconBtn.frame = CGRectMake(0, 0, 80*bili, 80*bili);
    iconBtn.center = CGPointMake(SCREEN_WIDTH/2, 100*bili);
    [iconBtn sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",tHost_URL,model.userImg]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"headIcon"]];
    [iconBtn addTarget:self action:@selector(updateInfo) forControlEvents:UIControlEventTouchUpInside];
    iconBtn.clipsToBounds = YES;
    iconBtn.layer.cornerRadius = 30*bili;
    [headerImage addSubview:iconBtn];
    
    NSString * userN = model.alias;
    nameLabel = [[UILabel alloc]initWithTitle:userN.length<=0? model.mobilePhone : userN font:18*bili color:[UIColor whiteColor]];
    nameLabel.font = [UIFont boldSystemFontOfSize:18*bili];
    nameLabel.frame = CGRectMake(0, 0, 200, 20*bili);
    nameLabel.center = CGPointMake(SCREEN_WIDTH/2, CGRectGetMaxY(iconBtn.frame)+15*bili);
    nameLabel.textAlignment = 1;
    [headerImage addSubview:nameLabel];
    
    return headerImage;
}
-(void)updateInfo{
    
}
-(void)loginClick{
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [UIView new];
    return view;
}
-(UITableView *)myTableView{
    if (_myTableView == nil) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.contentView.height) style:UITableViewStyleGrouped];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.backgroundColor = kBackgroudColor;
        _myTableView.tableFooterView = [UIView new];
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableView.estimatedRowHeight = 0;
        _myTableView.estimatedSectionHeaderHeight = 0;
        _myTableView.estimatedSectionFooterHeight = 0;
        _myTableView.scrollEnabled =NO;
    }
    return _myTableView;
}

@end
